package com.uaroadshow.finale.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.persistence.annotation.Dao;
import com.uaroadshow.entity.trade.Product;
import com.uaroadshow.entity.trade.ProductStat;
import com.uaroadshow.finale.dao.ProductDao;
import com.uaroadshow.finale.service.ProductService;

/**
 *
 * @author Ark
 *
 */
@Service("productService")
public class ProductServiceImpl extends DataServiceImpl<Product> implements ProductService {

    @Dao
    private ProductDao productDao;
    
    @Autowired
    private GenericDaoSupport genericDaoSupport;
    
    /* (non-Javadoc)
     * @see com.uaroadshow.finale.service.ProductService#list()
     */
    public List<Product> list() {
        List<Product> products = genericDaoSupport.loadAll(Product.class);
        return products;
    }
    
    /* (non-Javadoc)
     * @see com.uaroadshow.finale.service.ProductService#list(com.uaroadshow.entity.trade.Product)
     */
    public List<Product> list(Product product) {
        return productDao.listChild(product);
    }
    
    /* (non-Javadoc)
     * @see com.uaroadshow.finale.service.ProductService#getRemaining()
     */
    public Map<String, ProductStat> getRemaining() {
        
        Map<String, ProductStat> result = new HashMap<String, ProductStat>();
        
        List<ProductStat> stats = productDao.listStat();
        for (ProductStat stat : stats) {
            result.put(stat.getProduct().getIdString(), stat);
        }
        
        return result;
        
    }
    
}
